//
//  VisiterViewController.swift
//  weibo10
//
//  Created by 晁岳山 on 15/10/15.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit

class VisiterViewController: UITableViewController {
    
    private var userLogon: Bool = UserAccountViewModel.sharedUserViewMModel.login
    var visiters: visiterView?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //如果登陆  显示登陆界面  否则显示未登录界面
        userLogon ? super.loadView() : setupVisiterView()
    }
}
///设置未登录界面布局
extension VisiterViewController {
    func setupVisiterView() {
        visiters = visiterView()
        view = visiters
        //添加按钮点击事件
        visiters?.registerBtn.addTarget(self, action: "clickRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visiters?.loginBtn.addTarget(self, action: "clickLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "clickLogin")
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "clickRegister")
    }
    
}
// MARK: - 实现事件点击方法
extension VisiterViewController {
    func clickRegister() {
        print("注册")
    }
    func clickLogin() {
        //点击登录按钮  modal出一个控制器
        let vc = oAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        //控制器默认的是没有背景颜色的  如果不设置背景颜色  回影响渲染效果  
        //在开发中 我们一般都设置背景颜色
        presentViewController(nav, animated:true, completion: nil)
    }
}